package query

import (
	"context"
	"ddd-practice/domain"
)

type ProductAvailability struct {
	Id int
}

type ProductAvailabilityHandler struct {
	productRepo domain.Repository
}

func NewProductAvailabilityHandler(repository domain.Repository) ProductAvailabilityHandler {
	return ProductAvailabilityHandler{
		productRepo: repository,
	}
}

func (h ProductAvailabilityHandler) Handle(ctx context.Context, query ProductAvailability) (bool, error) {
	product, err := h.productRepo.GetProduct(ctx, query.Id)
	if err != nil {
		return false, err
	}
	return product.IsAvailable(), nil
}
